package br.com.mmm.javacenter.framework.view.taglib.helper;

import java.io.IOException;
import java.io.Writer;
import java.util.Calendar;

import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.tagext.JspFragment;

import br.com.mmm.javacenter.framework.annotations.RenderComponent;
import br.com.mmm.javacenter.framework.formatters.DateFormat;

@RenderComponent({
	Calendar.class
})
public class InputDate extends Input  {
	private boolean somenteLeituraDate;
	
	public InputDate() {
	
	}
	public InputDate(JspContext context, JspFragment fragment) {
		super(context, fragment);
	}
	
	public void before() throws IOException {
		this.somenteLeituraDate = isSomenteLeitura();
		setMaxLength(10);
		if(getValue()!=null)
			setValue(DateFormat.simpleDate.format(((Calendar) getValue()).getTime()));
	}
	public void attributes() throws IOException {
		if(somenteLeituraDate){
			writer.write(getAtributo("readonly", "readonly"));
		}else{
			writer.write(getAtributo("class", "date"));
		}
	}

}
